﻿@{
    ViewBag.Title = "打印表单";
    if (!WebMvc.Common.Tools.CheckLogin() && !YJ.Platform.WeiXin.Organize.CheckLogin())
    {
        Response.End();
        return;
    }
}

<link href="~/Scripts/FlowRun/Forms/flowform_print.css" rel="stylesheet" />
<style type="text/css" media="print">
    .Noprint { display: none; }
</style>

<div id="buttondiv" class="Noprint" style="margin:5px 0 0 15px;">
    <button onclick="print1();" class="mybutton" style="margin-right:4px;">确认打印</button>
    @if("1" != Request.QueryString["ismobile"]){
        <button class="mybutton" onclick="window.close();">取消关闭</button>
    }
</div>
<div style="width:98%; margin:-20px auto 0 auto;">
    @{
        string flowid = Request.QueryString["flowid"];
        string stepid = Request.QueryString["stepid"];
        string instanceid = Request.QueryString["instanceid"];
        string taskid = Request.QueryString["taskid"];
        string groupid = Request.QueryString["groupid"];
        bool isMobile = "1" == Request.QueryString["ismobile"];
        if (instanceid.IsNullOrEmpty())
        {
            instanceid = Request.QueryString["instanceid1"];
        }

        YJ.Platform.WorkFlow bworkFlow = new YJ.Platform.WorkFlow();
        YJ.Platform.WorkFlowTask btask = new YJ.Platform.WorkFlowTask();

        YJ.Data.Model.WorkFlowInstalled wfInstalled = bworkFlow.GetWorkFlowRunModel(flowid);
        if (wfInstalled == null)
        {
            Response.Write("未找到流程运行实体");
            Response.End();
            return;
        }
        var steps = wfInstalled.Steps.Where(p => p.ID == stepid.ToGuid());
        if (steps.Count() == 0)
        {
            Response.Write("未找到当前步骤");
            Response.End();
            return;
        }
        var currentStep = steps.First();
        if (currentStep.Forms.Count() == 0)
        {
            Response.Write("当前步骤没有表单");
            Response.End();
            return;
        }

        Guid formID = Guid.Empty;
        var formSet = currentStep.Forms.First();
        if (!isMobile)
        {
            formID = formSet.ID;
        }
        else
        {
            formID = formSet.IDApp.IsEmptyGuid() ? formSet.ID : formSet.IDApp;
        }
        var form = new YJ.Platform.AppLibrary().Get(formID);
        if (form != null)
        {
            string src = form.Address;
            if (!src.IsNullOrEmpty())
            {
                src = src.Trim1().StartsWith("/") ? WebMvc.Common.Tools.BaseUrl + src : src;
                var extName = System.IO.Path.GetExtension(src).ToLower();
                if (extName.StartsWith(".cshtml"))
                {
                    @RenderPage(src)
                }
                else
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    System.IO.TextWriter tw = new System.IO.StringWriter(sb);
                    Server.Execute(src, tw);
                    @Html.Raw(sb.ToString().RemovePageTag())
                }
            }
        }
    }
    </div>
    <div style="margin-top:-10px;">
        @RenderPage("ShowComment.cshtml")
    </div>
    <script type="text/javascript">
        function print1()
        {
            window.print();
        }
    </script>